package com.wsd.smartcarwasher.service;

import com.wsd.smartcarwasher.dao.MessagesMapper;
import com.wsd.smartcarwasher.domain.Messages;
import com.wsd.smartcarwasher.domain.Pagination;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MessagesService {
    @Resource
    private MessagesMapper messagesMapper;

    /**
     * 消息列表查询
     * @param userId
     * @param page
     * @return
     */
    public Pagination<Messages> getMessages(String userId, int page) {
        Messages m = new Messages();
        m.setSpeaker(userId);
        List<Messages>  lsm = messagesMapper.selectAll(m);
        return new Pagination<Messages>(page,20,lsm);
    }

    public int addMsg(Messages msg) {
        return  messagesMapper.insertSelective(msg);
    }


    public int addMsByM(Messages msg) {
        return  messagesMapper.updateByPrimaryKeySelective (msg);
    }


    public Pagination<Messages> getMessages(int page,int pageSiz,Messages m) {
        List<Messages>  lsm = messagesMapper.selectAll(m);
        return new Pagination<Messages>(page,pageSiz,lsm);
    }

    public int delete(String id) {
        return messagesMapper.removeByMessagesId(id);
    }
}
